package ma.ensao.evalmetrics.util.javaProjects;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/*
* Calcul la metrique MHF
*/
public class MHFMetric {
	File sourceFile;
	double mhf= 0;
	int nbMethods=0;
	public double getMhf() {
		return mhf;
	}
	public void setMhf(double mhf) {
		this.mhf = mhf;
	}
	public MHFMetric(File file) throws FileNotFoundException, IOException{
		setSourceFile(file);
		JavaMethodsAttributes JM= new JavaMethodsAttributes(getSourceFile());
		JM.countMethods();
		JM.countPrivateMethods();
		// Calcule MHF pour tout les classes
		
		double nmbre=0;
		for (int i = 0; i < JM.getNumberClasses(); i++) {
			if (JM.getNumberPrivateMethods()[i]==0 || JM.getNumberMethods()[i]==0){
				nmbre=0;
				mhf +=nmbre; 
			}else{
				nmbre =(double) JM.getNumberPrivateMethods()[i]/JM.getNumberMethods()[i];
				nbMethods += JM.getNumberPrivateMethods()[i];
				mhf +=nmbre; 
			}
		}
		// Calcul la moyenne de MHF
		setMhf(mhf/JM.getNumberClasses());
		this.setNbMethods(nbMethods);
	}
	public File getSourceFile() {
		return sourceFile;
	}
	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}
	public int getNbMethods() {
		return nbMethods;
	}
	public void setNbMethods(int nbMethods) {
		this.nbMethods = nbMethods;
	}
}
